package com.boatAnchorAssistant.service.repository.impl;

import com.boatAnchorAssistant.pojo.entity.ExpandValue;
import com.boatAnchorAssistant.service.mapper.ExpandValueMapper;
import com.boatAnchorAssistant.service.repository.in.ExpandValueRepository;
import nirvana.core.repository.Repository;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.stream.Collectors;

/**
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@Service
public class ExpandValueRepositoryImpl extends Repository<ExpandValueMapper, ExpandValue> implements ExpandValueRepository {

    private final ExpandValueMapper mapper;

    public ExpandValueRepositoryImpl(ExpandValueMapper mapper) {
        this.mapper = mapper;
    }


    /**
     * 获取拓展字段
     *
     * @param recordId
     * @return
     */
    @Override
    public Map<String, String> getExpandDate(Long recordId) {
        ExpandValue t = new ExpandValue();
        t.setRecordId(recordId);
        Map<String, String> map = getListByEntity(t)
                .stream()
                .collect(Collectors.toMap(ExpandValue::getName, ExpandValue::getValue));

        return map;
    }

    /**
     * 清空
     *
     * @param recordId
     */
    @Override
    public void clean(Long recordId) {
        if (recordId == null) {
            return;
        }

        ExpandValue t = new ExpandValue();
        t.setRecordId(recordId);
        mapper.delete(getWrapper(t));
    }
}